<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Custom Confirm Box</title>
  <style>
    /* 样式 */
    .modal {
      display: none; /* 默认隐藏 */
      position: fixed;
      z-index: 1;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      overflow: auto;
      background-color: rgba(0,0,0,0.4); /* 半透明背景 */
    }
    .modal-content {
      background-color: #fff;
      margin: 15% auto;
      padding: 20px;
      border: 1px solid #888;
      width: 80%;
      max-width: 300px;
      text-align: center;
    }
    .modal-buttons {
      margin-top: 20px;
    }
    .modal-buttons button {
      margin: 0 10px;
    }
  </style>
</head>
<body>
<h2>Custom Confirm Box Example</h2>
<button onclick="showConfirmBox()">Show Confirm Box</button>

<!-- 模态框 -->
<div id="myModal" class="modal">
  <div class="modal-content">
    <p>Are you sure you want to delete this item?</p>
    <div class="modal-buttons">
      <button onclick="confirmAction(true)">Yes</button>
      <button onclick="confirmAction(false)">No</button>
    </div>
  </div>
</div>

<script>
  function showConfirmBox() {
    document.getElementById('myModal').style.display = 'block';
  }

  function confirmAction(result) {
    document.getElementById('myModal').style.display = 'none';
    if (result) {
      console.log("User confirmed the action.");
      // 执行删除操作
    } else {
      console.log("User canceled the action.");
    }
  }
</script>
</body>
</html>
